package guda.stark.biz.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import guda.stark.biz.OwnerBiz;
import guda.stark.dal.dao.OwnerDAO;
import guda.stark.dal.dataobject.OwnerDO;
import guda.grape.autogen.common.page.BaseQuery;
import guda.grape.autogen.common.page.BizResult;

public class OwnerBizImpl implements OwnerBiz{

    private final static Logger logger = LoggerFactory.getLogger(OwnerBizImpl.class);

    @Autowired
    private OwnerDAO ownerDAO;

    public BizResult detail(long id) {
        BizResult bizResult = new BizResult();
        try{
            OwnerDO ownerDO = ownerDAO.getOwnerById(id);
            bizResult.data.put("ownerDO", ownerDO);
            bizResult.success = true;
        }catch(Exception e){
            logger.error("query Owner error",e);
        }
        return bizResult;
}

    public BizResult list(BaseQuery baseQuery) {
        BizResult bizResult = new BizResult();
        try {
            int totalCount = ownerDAO.countForPage(baseQuery);
            baseQuery.setTotalCount(totalCount);
            List<OwnerDO> ownerList = ownerDAO.selectForPage(baseQuery);
            bizResult.data.put("ownerList", ownerList);
            bizResult.data.put("query", baseQuery);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("view Owner list error", e);
        }
            return bizResult;
     }

    public BizResult delete(long id) {
        BizResult bizResult = new BizResult();
        try {
            ownerDAO.delOwnerById(id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("delete owner error", e);
        }
        return bizResult;
    }

    public BizResult create(OwnerDO ownerDO) {
        BizResult bizResult = new BizResult();
        try {
            long id = ownerDAO.insert(ownerDO);
            bizResult.data.put("id", id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("create Owner error", e);
        }
        return bizResult;
    }

    @Override
    public BizResult update(OwnerDO ownerDO) {
        BizResult bizResult = new BizResult();
        try {
            ownerDAO.updateByIdSelective(ownerDO);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("update Owner error", e);
        }
        return bizResult;
    }


}
